package com.cdut.hwadeefsc.mapper;

import com.cdut.hwadeefsc.entity.comments;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface commentsMapper {
    // 修正参数类型为Long（与实体类studentId类型一致）
    @Select("SELECT * FROM comments WHERE student_id = #{studentId} ORDER BY created_at DESC")
    List<comments> findByStudentId(Long studentId);

    // 修正参数类型为Long，字段semester→term（匹配实体类term属性）
    @Select("SELECT * FROM comments WHERE student_id = #{studentId} AND term = #{term}")
    List<comments> findByStudentIdAndTerm(@Param("studentId") Long studentId, @Param("term") String term);

    // 修正字段映射（semester→term，comment_content→content）
    @Insert("INSERT INTO comments (student_id, teacher_id, content, term, created_at) " +
            "VALUES (#{studentId}, #{teacherId}, #{content}, #{term}, #{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(comments comment);

    // 修正字段comment_content→content（匹配实体类content属性）
    @Update("UPDATE comments SET content = #{content} WHERE id = #{id}")
    int update(comments comment);

    // 修正参数类型为Long（与实体类id类型一致）
    @Delete("DELETE FROM comments WHERE id = #{id}")
    int delete(Long id);
}




